package jjn.round1;

/**
 * @author Jjn
 * @since 2022/8/28 18:58
 */
public class LeetCode724_FindPivotIndex_Solution2 {

    public int pivotIndex(int[] nums) {
        int total = 0;
        for (int num : nums) {
            total += num;
        }
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (count * 2 == total - nums[i]) {
                return i;
            }
            count += nums[i];
        }
        return -1;
    }
}
